<template>
  <a-dropdown :trigger="['hover']" placement="bottomCenter" v-model="show" >
    <div slot="overlay">
      <a-spin :spinning="loading">
        <a-list bordered :data-source="data" class="HeaderNotice">
          <a-list-item slot="renderItem" slot-scope="item" class="HeaderNotice-item">
            <p>{{item.time}}  {{item.type}}</p>
            <p>{{item.content}}</p>
          </a-list-item>
          <div slot="footer">
            <a-button type="link" @click="goList">
              查看全部报警
            </a-button>
          </div>
        </a-list>
      </a-spin>
    </div>
    <span @click="fetchNotice" class="header-notice">
      <a-badge class="notice-badge" count="12">
        <a-icon :class="['header-notice-icon']" type="bell" />
      </a-badge>
    </span>
  </a-dropdown>
</template>

<script>
export default {
  name: 'HeaderNotice',
  data () {
    return {
      loading: false,
      show: false,
      data: [
        {time: '2020-07-12 13:23:43', type: '位置异常', content: '王玉（××机构）当前位置：湖北省武汉市东湖新技术开发区关山大道光谷创意大厦。  '},
        {time: '2020-07-12 13:23:43', type: '心率', content: '王玉（××机构）报警值：127bpm '},
        {time: '2020-07-12 13:23:43', type: '血压', content: '王玉（××机构）报警值：127bpm '},
        {time: '2020-07-12 13:23:43', type: '位置异常', content: '王玉（××机构）报警值：127/74mmHg '},
      ]
    }
  },
  computed: {
  },
  methods: {
    goList() {
      this.$router.push('/UserManagement/alarmRecord');
    },
    fetchNotice () {
      if (this.loading) {
        this.loading = false
        return
      }
      this.loadding = true
      setTimeout(() => {
        this.loadding = false
      }, 1000)
    }
  }
}
</script>

<style lang="less">
  .HeaderNotice{
    background: #fff;
    border-radius: 0;
    max-width: 280px;
    .ant-list-footer{
      padding: 0!important;
      text-align: right;
      button{
        font-size: 12px!important;
      }
    }
    &-item{
      display: flex;
      flex-direction: column;
      padding: 15px 20px!important;
      align-items: flex-start;
      cursor: pointer;
      transition: all .3s linear;
      &:hover{
        background: rgba(166, 199, 226, 0.39);
      }
      p{
        margin: 0;
        padding: 0;
        font-size: 14px;
      }
    }
  }
  .header-notice{
    display: inline-block;
    transition: all 0.3s;
    span {
      vertical-align: initial;
    }
    .notice-badge{
      color: inherit;
      .header-notice-icon{
        font-size: 16px;
        padding: 4px;
      }
    }
  }
  .dropdown-tabs{
    background-color: @base-bg-color;
    box-shadow: 0 2px 8px @shadow-color;
    border-radius: 4px;
    .tab-pane{
      padding: 0 24px 12px;
      min-height: 250px;
    }
  }
</style>
